﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml;


namespace GameBanChim_Version1
{
    public class SpecialSkill : Skill
    {
        bool _isUse = false;

        public bool IsUse
        {
            get { return _isUse; }
            set { _isUse = value; }
        }

        int _nDelayTime = 5;
        int _iDelayTime = 0;

        bool _finish = false;

        public void Reset()
        {
            Isprite = 0;
            _finish = false;
            _isUse = false;
            _iDelayTime = 0;
            //Y = 545;
        }

        SoundEffect _sound;

        public void MyInit(ContentManager Content)
        {
            Isprite = 0;
            Nsprite = 2;
            Sprite = new MySprite[Nsprite];
            Texture2D[] _temp = new Texture2D[4];
            for (int i = 0; i < 4; i++)
            {
                _temp[i] = Content.Load<Texture2D>("Skill/Special/Idle/" + i.ToString("00"));
            }
            Sprite[0] = new MySprite(_temp, 0, 0, 2);

            _temp = new Texture2D[8];
            for (int i = 0; i < 8; i++)
            {
                _temp[i] = Content.Load<Texture2D>("Skill/Special/Clicked/" + i.ToString("00"));
            }
            Sprite[1] = new MySprite(_temp, 0, 0, 2);
            X = 390;
            Y = 545;
            Rec = new Rectangle((int)X, (int)Y, Sprite[0].Texture2D[0].Width, Sprite[0].Texture2D[0].Height);

            _sound = Content.Load<SoundEffect>("Sound/BulletSkill");
        }

        public override void Update(GameTime gameTime)
        {
            if (_finish)
                return;
            if (_iDelayTime == _nDelayTime - 1)
            {
                if (!_isUse)
                {
                    base.Update(gameTime);
                    //Sprite[Isprite].Itexture2D = (Sprite[Isprite].Itexture2D + 1) % Sprite[Isprite].Ntexture2D;
                    if (Rec.Contains(GlobalVariables.CurMouseState.X, GlobalVariables.CurMouseState.Y) && GlobalVariables.CurMouseState.LeftButton == ButtonState.Pressed)
                    {
                        _isUse = true;
                        Isprite = 1;
                        Y -= 10;
                        _sound.Play();
                    }
                }
                else
                {
                    base.Update(gameTime);
                    //Sprite[Isprite].Itexture2D = (Sprite[Isprite].Itexture2D + 1) % Sprite[Isprite].Ntexture2D;
                    if (Sprite[Isprite].Itexture2D == 0)
                    {
                        _finish = true;
                    }
                }
                _iDelayTime = 0;
            }
            else
                _iDelayTime = (_iDelayTime + 1) % _nDelayTime;
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if (!_finish)
            {
                //base.Draw(gameTime, spriteBatch);
                spriteBatch.Draw(Sprite[Isprite].Texture2D[Sprite[Isprite].Itexture2D], new Vector2(X, Y), Color.White);
            }
        }
    }
}
